package top.qingyunge.autumn.vo;

import lombok.Data;

import java.io.Serial;
import java.io.Serializable;

@Data
public class Result<T> implements Serializable {
    @Serial
    private static final long serialVersionUID = 3886133510513339083L;
    /**
     * 响应码
     */
    private Integer code;
    private T content;
    private String message;
    private Boolean success;
    private long timestamp;

    public Result() {
        // 返回结果时间
        this.timestamp = System.currentTimeMillis();
    }
    public static <Boolean> Result<Boolean> success() {
        Result<Boolean> response = new Result<>();
        response.code = 200;
        response.message = "ok";
        response.success = true;
        return response;
    }

    public static <T> Result<T> success(T data) {
        Result<T> response = new Result<>();
        response.code = 200;
        response.message = "ok";
        response.success = true;
        response.content = data;
        return response;
    }

    public static <T> Result<T> error(Integer code, String message) {
        Result<T> response = new Result<>();
        response.code = code;
        response.message = message;
        response.success = false;
        response.content = null;
        return response;
    }

}
